package com.tanhua.common.utils;

import com.tanhua.common.pojo.User;

public class UserThreadLocal {
    private static final ThreadLocal<User> LOCAL = new ThreadLocal<>();

    private UserThreadLocal() {
    }

    /**
     * 将User对象放入ThreadLocal
     *
     * @param user 要绑定在线程上的User对象
     */
    public static void set(User user) {
        LOCAL.set(user);
    }

    /**
     * 返回当前线程上绑定的User对象
     *
     * @return 绑定在线程伤上的User对象
     */
    public static User get() {
        return LOCAL.get();
    }

    /**
     * 删除当前线程上绑定的User对象
     */
    public static void remove() {
        LOCAL.remove();
    }
}
